home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Binaries / examples / kb / prelude.ml < prev    next >
Encoding:
Text File  |  1993-09-24  |  632 b   |  24 lines  |  [TEXT/ttxt]

  1. (**************** A few general-purpose functions *******************)
  2.  
  3. let fold f = fold_rec where rec fold_rec a1 = function
  4.     [] -> (a1,[])
  5.   | b1::bl ->
  6.       let (a2,c2) = f a1 b1 in
  7.       let (a,cl) = fold_rec a2 bl in
  8.         (a, c2::cl)
  9. ;;
  10.  
  11. let try_find f = try_find_rec where rec try_find_rec = function
  12.      []  -> failwith "try_find"
  13.   | a::L -> try f a with Failure _ -> try_find_rec L
  14. ;;
  15.  
  16. let partition p = part_rec where rec part_rec = function
  17.      []  -> [],[]
  18.   | a::L -> let (pos,neg) = part_rec L in
  19.               if p a then  a::pos, neg else pos, a::neg
  20. ;;
  21.  
  22. let message s = print_string s; print_newline()
  23. ;;
  24.